package cn.wolfcode.luowowo.flight.service.impl;

import cn.wolfcode.luowowo.common.util.AjaxResult;
import cn.wolfcode.luowowo.common.util.Assert;
import cn.wolfcode.luowowo.flight.mapper.FlightMapper;
import cn.wolfcode.luowowo.flight.query.FlightQueryObject;
import cn.wolfcode.luowowo.flight.service.IFlightSearchService;
import cn.wolfcode.luowowo.flight.template.FlightTemplate;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
@Service
public class FlightSearchServiceImpl implements IFlightSearchService {
    @Autowired
    private FlightMapper flightMapper;
    @Override
    public List<FlightTemplate> listByHotTop20(FlightQueryObject qo) {
        return flightMapper.selectByHotTop20(qo);
    }

    @Override
    public List<FlightTemplate> listByInitialABCDE() {
        return flightMapper.selectByInitialABCDE();
    }

    @Override
    public List<FlightTemplate> listByInitialFGHJ() {
        return flightMapper.selectByInitialFGHJ();
    }

    @Override
    public List<FlightTemplate> listByInitialKLMNP() {
        return flightMapper.selectByInitialKLMNP();
    }

    @Override
    public List<FlightTemplate> listByInitialQRSTW() {
        return flightMapper.selectByInitialQRSTW();
    }

    @Override
    public List<FlightTemplate> listByInitialXYZ() {
        return flightMapper.selectByInitialXYZ();
    }

    @Override
    public AjaxResult listByPortAndTime(FlightQueryObject qo) {
        AjaxResult result = new AjaxResult();
        try {
            //检验查询条件是否为空
            Assert.hasLength(qo.getOrgCity(),"出发城市不能为空");
            Assert.hasLength(qo.getDstCity(),"到达城市不能为空");
            //Assert.hasLength(qo.getDeptTime(),"出发时间不能为空");

            List<FlightTemplate> flightInfos = flightMapper.selectByPortAndTime(qo);
            result.addData(flightInfos);

        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }

        return result;
    }
}
